package com.flyu.mySocket;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class UdpServerDome1 {
    public static void main(String[] args) throws Exception {
        // 1. 开放端口
        DatagramSocket socket = new DatagramSocket(9999);

        // 2. 接收数据
        byte[] bytes = new byte[1024];
        DatagramPacket packet = new DatagramPacket(bytes, 0, bytes.length);
        socket.receive(packet); // 阻塞式接收

        // 打印
        System.out.println(packet.getAddress().getHostAddress());
        System.out.println(new String(packet.getData(),0,packet.getLength()));

        // 3. 关闭连接
        socket.close();

    }
}
